<template>
<a-modal :maskClosable="false"
        :title="title"
        :width="800"
        :visible="visible"
        :confirmLoading="confirmLoading"
        @ok="handleOk"
        @cancel="handleCancel"
        cancelText="关闭">

<a-spin :spinning="confirmLoading">
   <a-form-model ref="form"  v-bind="layout"  :model="model" :rules="validatorRules">

      <a-form-model-item label="${column.columnComment}"  prop="id">
           <a-input placeholder="请输入$comment"  v-model="model.id"  />
        </a-form-model-item >
      <a-form-model-item label="租户id" required prop="tenantId">
           <a-input placeholder="请输入租户id"  v-model="model.tenantId"  />
        </a-form-model-item >
      <a-form-model-item label="下单会员id" required prop="memberId">
           <a-input placeholder="请输入下单会员id"  v-model="model.memberId"  />
        </a-form-model-item >
      <a-form-model-item label="医院机构编码" required prop="orgCode">
           <a-input placeholder="请输入医院机构编码"  v-model="model.orgCode"  />
        </a-form-model-item >
      <a-form-model-item label="更新人员" required prop="updateUser">
           <a-input placeholder="请输入更新人员"  v-model="model.updateUser"  />
        </a-form-model-item >
      <a-form-model-item label="最近一次更新时间" required prop="updateTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.updateTime"  />
        </a-form-model-item >
      <a-form-model-item label="创建人员" required prop="createUser">
           <a-input placeholder="请输入创建人员"  v-model="model.createUser"  />
        </a-form-model-item >
      <a-form-model-item label="添加时间" required prop="createTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.createTime"  />
        </a-form-model-item >
      <a-form-model-item label="是否已经删除，0，否；1，已删除" required prop="isDeleted">
           <a-input placeholder="请输入是否已经删除，0，否；1，已删除"  v-model="model.isDeleted"  />
        </a-form-model-item >
      <a-form-model-item label="商户订单号"  prop="orderSn">
           <a-input placeholder="请输入商户订单号"  v-model="model.orderSn"  />
        </a-form-model-item >
      <a-form-model-item label="状态，0未支付，1已支付"  prop="status">
           <a-input placeholder="请输入状态，0未支付，1已支付"  v-model="model.status"  />
        </a-form-model-item >
      <a-form-model-item label="项目分类 取h_category" required prop="categoryId">
           <a-input placeholder="请输入项目分类 取h_category"  v-model="model.categoryId"  />
        </a-form-model-item >
      <a-form-model-item label="项目ID.  取door_service_project" required prop="projectId">
           <a-input placeholder="请输入项目ID.  取door_service_project"  v-model="model.projectId"  />
        </a-form-model-item >
      <a-form-model-item label="项目名称" required prop="project">
           <a-input placeholder="请输入项目名称"  v-model="model.project"  />
        </a-form-model-item >
      <a-form-model-item label="总费用" required prop="amount">
           <a-input placeholder="请输入总费用"  v-model="model.amount"  />
        </a-form-model-item >
      <a-form-model-item label="收费方式 0天 1包月 2包年" required prop="amountType">
           <a-input placeholder="请输入收费方式 0天 1包月 2包年"  v-model="model.amountType"  />
        </a-form-model-item >
      <a-form-model-item label="服务所需时间分数" required prop="serviceTime">
           <a-input placeholder="请输入服务所需时间分数"  v-model="model.serviceTime"  />
        </a-form-model-item >
      <a-form-model-item label="项目图片"  prop="projectImg">
           <a-input placeholder="请输入项目图片"  v-model="model.projectImg"  />
        </a-form-model-item >
      <a-form-model-item label="上门日期" required prop="appointmentDate">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.appointmentDate"  />
        </a-form-model-item >
      <a-form-model-item label="上门起始时间段" required prop="appointmentBeginTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.appointmentBeginTime"  />
        </a-form-model-item >
      <a-form-model-item label="上门结束时间段" required prop="appointmentEndTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.appointmentEndTime"  />
        </a-form-model-item >
      <a-form-model-item label="收货人的国家,用户页面填写,默认取值于表user_address,其id对应的值在region" required prop="country">
           <a-input placeholder="请输入收货人的国家,用户页面填写,默认取值于表user_address,其id对应的值在region"  v-model="model.country"  />
        </a-form-model-item >
      <a-form-model-item label="收货人的省份,用户页面填写,默认取值于表user_address, 其id对应的值在region" required prop="province">
           <a-input placeholder="请输入收货人的省份,用户页面填写,默认取值于表user_address, 其id对应的值在region"  v-model="model.province"  />
        </a-form-model-item >
      <a-form-model-item label="收货人的城市,用户页面填写,默认取值于表user_address,其id对应的值在region" required prop="city">
           <a-input placeholder="请输入收货人的城市,用户页面填写,默认取值于表user_address,其id对应的值在region"  v-model="model.city"  />
        </a-form-model-item >
      <a-form-model-item label="收货人的地区,用户页面填写,默认取值于表user_address,其id对应的值在region" required prop="district">
           <a-input placeholder="请输入收货人的地区,用户页面填写,默认取值于表user_address,其id对应的值在region"  v-model="model.district"  />
        </a-form-model-item >
      <a-form-model-item label="收货人的详细地址,用户页面填写,默认取值于表user_address" required prop="address">
           <a-input placeholder="请输入收货人的详细地址,用户页面填写,默认取值于表user_address"  v-model="model.address"  />
        </a-form-model-item >
      <a-form-model-item label="收货人的详细地址ID" required prop="addressId">
           <a-input placeholder="请输入收货人的详细地址ID"  v-model="model.addressId"  />
        </a-form-model-item >
      <a-form-model-item label="患者id" required prop="patientId">
           <a-input placeholder="请输入患者id"  v-model="model.patientId"  />
        </a-form-model-item >
      <a-form-model-item label="收货人的手机,用户页面填写,默认取值于表user_address" required prop="mobile">
           <a-input placeholder="请输入收货人的手机,用户页面填写,默认取值于表user_address"  v-model="model.mobile"  />
        </a-form-model-item >
      <a-form-model-item label="订单类型" required prop="orderType">
           <a-input placeholder="请输入订单类型"  v-model="model.orderType"  />
        </a-form-model-item >
      <a-form-model-item label="备注" required prop="remark">
           <a-input placeholder="请输入备注"  v-model="model.remark"  />
        </a-form-model-item >
      </a-form-model>
    </a-spin>
</a-modal>
</template>

<script>
  import { httpAction,putAction,getAction,postAction} from '@api/manage'

  export default {
    name: "hChCareDoorOrderModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        layout: {
           labelCol: { span: 4 },
           wrapperCol: { span: 14 },
        },
        confirmLoading: false,
        validatorRules:{
        tenantId:[{ required: true, message: '请输入租户id!' }],
        memberId:[{ required: true, message: '请输入下单会员id!' }],
        orgCode:[{ required: true, message: '请输入医院机构编码!' }],
        updateUser:[{ required: true, message: '请输入更新人员!' }],
        updateTime:[{ required: true, message: '请输入最近一次更新时间!' }],
        createUser:[{ required: true, message: '请输入创建人员!' }],
        createTime:[{ required: true, message: '请输入添加时间!' }],
        isDeleted:[{ required: true, message: '请输入是否已经删除，0，否；1，已删除!' }],
        categoryId:[{ required: true, message: '请输入项目分类 取h_category!' }],
        projectId:[{ required: true, message: '请输入项目ID.  取door_service_project!' }],
        project:[{ required: true, message: '请输入项目名称!' }],
        amount:[{ required: true, message: '请输入总费用!' }],
        amountType:[{ required: true, message: '请输入收费方式 0天 1包月 2包年!' }],
        serviceTime:[{ required: true, message: '请输入服务所需时间分数!' }],
        appointmentDate:[{ required: true, message: '请输入上门日期!' }],
        appointmentBeginTime:[{ required: true, message: '请输入上门起始时间段!' }],
        appointmentEndTime:[{ required: true, message: '请输入上门结束时间段!' }],
        country:[{ required: true, message: '请输入收货人的国家,用户页面填写,默认取值于表user_address,其id对应的值在region!' }],
        province:[{ required: true, message: '请输入收货人的省份,用户页面填写,默认取值于表user_address, 其id对应的值在region!' }],
        city:[{ required: true, message: '请输入收货人的城市,用户页面填写,默认取值于表user_address,其id对应的值在region!' }],
        district:[{ required: true, message: '请输入收货人的地区,用户页面填写,默认取值于表user_address,其id对应的值在region!' }],
        address:[{ required: true, message: '请输入收货人的详细地址,用户页面填写,默认取值于表user_address!' }],
        addressId:[{ required: true, message: '请输入收货人的详细地址ID!' }],
        patientId:[{ required: true, message: '请输入患者id!' }],
        mobile:[{ required: true, message: '请输入收货人的手机,用户页面填写,默认取值于表user_address!' }],
        orderType:[{ required: true, message: '请输入订单类型!' }],
        remark:[{ required: true, message: '请输入备注!' }],
        },
        url: {
          add: "/system/hChCareDoorOrder",
          edit: "/system/hChCareDoorOrder",
        },
      }
    },
    created () {
        this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
          this.model = Object.assign({}, record);
          this.visible = true;
      },
      close () {
          this.$refs.form.clearValidate();
          this.$emit('close');
          this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
              method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                 that.$message.success(res.message);
                 that.$emit('ok');
              }else{
                 that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
            return false;
         }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>